package yxy.game.pm2.command.camptower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.CampTowerMessage;
import yxy.game.pm2.module.camptower.CampTowerModule;

import java.util.List;

/**
 * 阶段目标奖励领奖界面
 *
 * @ClassName CMD_CampTowerStageTargetUI
 * @Author jingtao-zheng
 * @Date 2022/8/5 12:10
 * @Version 1.0
 **/
@MessageType(proto = Command.CampTowerStageTargetUI, classtype = CampTowerMessage.CampTowerStageTargetUIRequest.class)
public class CMD_CampTowerStageTargetUI extends Command<CampTowerMessage.CampTowerStageTargetUIRequest> {
    @Override
    public void execute(MessageSource messageSource, CampTowerMessage.CampTowerStageTargetUIRequest request) throws Exception {
        String playerCode = messageSource.getTag();
        //获取阵营塔类型
        int type = request.getType().getNumber();
        CampTowerMessage.CampTowerStageTargetUIResponse.Builder response = CampTowerMessage.CampTowerStageTargetUIResponse.newBuilder();
        CampTowerModule towerModule = CampTowerModule.get(playerCode);
        List<Integer> levelReward = towerModule.getLevelReward().get(type);
        //返回已领取的奖励
        for (Integer levelRewardId : levelReward) {
            response.addBox(levelRewardId);
        }

        send(messageSource, response, Result.Success);
    }

    private void send(MessageSource messageSource, CampTowerMessage.CampTowerStageTargetUIResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
